<template>
  <div class="secindex">
    <!-- 右上角新增秒杀 -->
    <div class="radius">新增秒杀</div>
    <span>基本信息</span>
    <!-- 新增秒杀框 -->
    <div class="secindex-box">
      <el-form
        ref="ruleFormRef"
        :model="ruleForm"
        :rules="rules"
        label-width="120px"
        class="demo-ruleForm"
        :size="formSize"
        status-icon
      >
        <el-form-item label="秒杀标题" prop="name">
          <el-input v-model="ruleForm.name" placeholder="请填写秒杀标题" />
        </el-form-item>
        <el-form-item label="商品编号" prop="sid">
          <el-input v-model="ruleForm.sid" placeholder="编号" />
        </el-form-item>
        <el-form-item label="活动时间" required>
          <el-col :span="11">
            <el-form-item prop="date1">
              <el-date-picker
                v-model="ruleForm.date1"
                type="date"
                label="Pick a date"
                placeholder="选择日期"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col class="text-center" :span="2">
            <div style="padding-left: 10px">-</div>
          </el-col>
          <el-col :span="11">
            <el-form-item prop="date2">
              <el-time-picker
                v-model="ruleForm.date2"
                label="Pick a time"
                placeholder="选择时间"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="活动省区" prop="pro">
          <el-input
            v-model="ruleForm.pro"
            placeholder="添加省区 全国"
            style="width: 150px"
          />
          <div style="font-size: 12px; padding-left: 15px; color: #ccc">
            已选城市 山东省 浙江省
          </div>
        </el-form-item>
      </el-form>
      <el-row class="mb-4" style="padding: 10px 0 0 200px">
        <el-button @click="resetForm(ruleFormRef)">取消</el-button>
        <el-button type="danger" @click="submitForm(ruleFormRef)"
          >创建</el-button
        >
      </el-row>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from "vue";
import type { FormInstance, FormRules } from "element-plus";
// import { ElMessage } from "element-plus";
export default defineComponent({
  setup() {
    // 新曾
    const formSize = ref("default");
    const ruleFormRef = ref<FormInstance>();
    const ruleForm = reactive({
      name: "",
      sid: "",
      date1: "",
      date2: "",
      pro: "",
    });

    const rules = reactive<FormRules>({
      name: [
        {
          required: true,
          message: "请填写秒杀标题",
          trigger: "blur",
        },
      ],
      sid: [
        {
          required: true,
          message: "请输入编号",
          trigger: "blur",
        },
      ],
      date1: [
        {
          type: "date",
          required: true,
          message: "请填写日期",
          trigger: "change",
        },
      ],
      date2: [
        {
          type: "date",
          required: true,
          message: "请填写时间",
          trigger: "change",
        },
      ],
      pro: [
        {
          required: true,
          message: "请输入省份",
          trigger: "blur",
        },
      ],
    });
    const submitForm = async (formEl: FormInstance | undefined) => {
      if (!formEl) return;
      await formEl.validate((valid, fields) => {
        if (valid) {
          console.log("submit!");
        } else {
          console.log("error submit!", fields);
        }
      });
    };
    const resetForm = (formEl: FormInstance | undefined) => {
      if (!formEl) return;
      formEl.resetFields();
      console.log(formEl);
    };
    const options = Array.from({ length: 10000 }).map((_, idx) => ({
      value: `${idx + 1}`,
      label: `${idx + 1}`,
    }));
    // let disabled = true;
    // const open2 = () => {
    //   // disabled = true;
    //   // if (!Object.values(ruleForm)) {
    //   ElMessage({
    //     message: "创建成功",
    //     type: "success",
    //   });
    // } else {
    //   console.log(Object.values(ruleForm));
    // }
    // disabled = true;
    // };
    return {
      formSize,
      ruleFormRef,
      ruleForm,
      rules,
      submitForm,
      resetForm,
      options,
      // open2,
      // disabled,
    };
  },
});
</script>

<style lang="less" scoped>
.secindex {
  background: #fff;
  margin-right: 10px;
  padding-top: 10px;
  border-radius: 20px;
  width: 100%;
  height: 100vh;
  min-width: 1217px;
  .radius {
    background: #ffdb92;
    width: 160px;
    height: 50px;
    border-radius: 0 25px 25px 0;
    margin-top: 16px;
    box-shadow: 0px 2px 1px 0px rgba(0, 0, 0, 0.5);
    padding-left: 20px;
    line-height: 50px;
    font-size: 18px;
    font-weight: bold;
  }
  span {
    display: block;
    padding: 32px 0 0 58px;
    font-weight: 400;
    font-size: 18px;
  }
}
.secindex-box {
  width: 450px;
  margin: 0 auto;
}
</style>
